package com.es.disped.service.datasource;

import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import com.es.disped.api.oj.user.HustUserService;
import com.es.disped.common.annotation.DynamicDataSource;
import com.es.disped.common.constant.DataSourceName;
import com.es.disped.common.spring.DataSourceContextHolder;
import com.es.disped.dao.oj.model.Users;
import com.es.disped.dao.oj.model.UsersExample;

@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations={
		"classpath:spring/applicationContext.xml",
		"classpath:spring/springMVC-servlet.xml",
})
public class ChangeDataSource {

	@Autowired
	HustUserService hustUserService;
	
	@Test
	public void test()
	{
		DataSourceContextHolder.setDataSource(DataSourceName.EXTEND.getName());
		System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+DataSourceContextHolder.getDataSource());
		List<Users> users=hustUserService.selectByExample(new UsersExample());
		if(users==null)
		{
			System.out.println(">>>>>>>>>>>>>>>>>>>>>> NULL");
		}else
		{
			for(Users users2:users)
			{
				System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>USER: "+users2);
			}
		}
		
	}
	
	@Test
	public void datasource()
	{
		DataSourceContextHolder.setDataSource(DataSourceName.EXTEND.getName());
		System.out.println(DataSourceContextHolder.getDataSource());
	}
}
